﻿using System.Windows.Input;

namespace AiMoWindows.Windows
{
    class RelayCommand : ICommand
    {

        public event EventHandler? CanExecuteChanged;
        readonly Action action;
        public RelayCommand(Action action)
        {
            this.action = action;
        }
        public bool CanExecute(object? parameter)
        {
            return true;
        }
        public void Execute(object? parameter)
        {
            action.Invoke();
        }
    }
    class RelayCommand<T> : ICommand
    {
        public event EventHandler? CanExecuteChanged;

        readonly Action<T> action;
        public RelayCommand(Action<T> action)
        {
            this.action = action;
        }
        public bool CanExecute(object? parameter)
        {
            return true;
        }
        public void Execute(object? parameter)
        {
            if (parameter is T t)
                action.Invoke(t);
        }
    }
}
